package jsyf.oa.web.wreport;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wreport.Template2ModuleFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Lenovo on 2017/12/11.
 */
@Api(value = "", description = "")
@Controller
@RequestMapping("/template2Module")
public class Template2ModuleController {
    @Autowired
    private Template2ModuleFacade template2ModuleFacade;

    @RequestMapping(value = "/config.json", method = RequestMethod.POST)
    public void config(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        Boolean result = template2ModuleFacade.config(jsonParam.getString("templateId"),jsonParam.getString("moduleIds"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(String.valueOf(result)));
    }


    @RequestMapping(value = "/getByTemplateId.json", method = RequestMethod.POST)
    public void getByTemplateId(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> result = template2ModuleFacade.getByTemplateId(jsonParam.getString("templateId"));
        ResponseUtils.putJsonResponse(response,BaseUtils.succsessArrRespond(result));
    }
}
